<template>
  <!-- 教务管理-约名师容器 -->
  <div class="orderForeignTeacher">
    <div class="content-foreign">
      <selectCourse ref="selectCourse" v-if="selectType===1" :orderForeignTeacherSelectCourse='null' @confirm="selectCourseConfirm" @cancel="selectCourseCancel"></selectCourse>
      <selectTeacher ref="selectTeacher" v-else :orderForeignTeacherSelectTeacher='null'
       @confirm="selectTeacherConfirm"
       @cancel="selectTeacherCancel"
       @showOrderForeignSyllabuslist="showOrderForeignSyllabuslist">
      </selectTeacher>
    </div>
  </div>
</template>

<script>
import selectCourse from "./orderForeign_selectCourse";
import selectTeacher from "./orderForeign_selectTeacher";
export default {
  components: { selectCourse, selectTeacher },
  props: ["orderForeignTeacher"],
  data() {
    return {
      /**选择类型：1-选择课程；2-选名师 */
      selectType:0,
    };
  },
  methods: {
    /**初始化数据
     * @param type 1-选择课程；2-选名师  弃用，根据当前约课数判断进入界面
     * @param classObj 班级信息
     * @param courseObj 排课列表
     * 
     */
    initBydata(data) {
      // debugger
      if (!data) return;
      let self=this;
      let clonedata=tool.clone(data);
      self.goToPageByCourseNumber(clonedata,false);
      this.$nextTick(()=>{
        //正常班级
        if(clonedata.classObj.classOrTrialClass===1){
          api.getClassById({classId:clonedata.classObj.classId}).then(function(d){
            if(d.result=='操作成功'){
              clonedata.classObj=d.class;
              self.goToPageByCourseNumber(clonedata);
            }
          });
        }
        //试听班级
        else if(clonedata.classObj.classOrTrialClass===2){
          api.auditionInfo({classId:clonedata.classObj.classId}).then(function(d){
            if(d.result=='操作成功'){
              clonedata.classObj=d.data;
              self.goToPageByCourseNumber(clonedata);
            }
          });
        }
        
      });
    },
    /**
     * 跳转判断
     * 只有约全部课程的才进入选课程界面
     */
    goToPageByCourseNumber(data,isgo=true){
      if(!data.classObj)return;
      // let leftcourseNum=data.classObj.syllabusEndNum-data.classObj.syllabusStartNum+1-data.classObj.feiboSyllabusOrderNum;
      let leftcourseNum=data.courseObj.length;//获取要约名师的节数
      
      let allcourseNum=data.classObj.feiboSyllabusNum||(data.classObj.syllabusEndNum-data.classObj.syllabusStartNum+1);
      if(leftcourseNum==allcourseNum){
        this.selectType=1;
        if(isgo)
          this.$nextTick(()=>{
            this.$refs['selectCourse'].initBydata(data);
          });
        
      }
      else{
        this.selectType=2;
        data.classObj.teacherCountry=tool.getDictNameByValue(data.classObj.foreignTeacherType,
        'foreign_teacher_type');
        // data.classObj.teacherType='专属和公共';
        data.classObj.payType='余额支付';
        if(isgo)
          this.$nextTick(()=>{
            this.$refs['selectTeacher'].initBydata(data);
          });
        else{
          this.$nextTick(()=>{
            this.$refs['selectTeacher'].resetPage();
          });
        }
      }
    },
    /**选课成功返回 */
    selectCourseConfirm(data){
      // console.log(data);
      this.selectType=2;
      this.$nextTick(()=>{
        this.$refs['selectTeacher'].initBydata(data);
      });
    },
    /**选课取消返回 */
    selectCourseCancel(data){
      this.$emit('cancel','data');
    },
    /**选外教成功返回 */
    selectTeacherConfirm(data){

    },
    /**选外教取消返回 */
    selectTeacherCancel(data){

    },
    showOrderForeignSyllabuslist(d){
      this.$emit('showOrderForeignSyllabuslist',d);
    }
  },
  mounted() {},
  computed: {},
  watch: {},
  created: function() {}
};
</script>

<style lang="scss">
.orderForeignTeacher {
  .content-foreign {
    // padding: 0 0.04rem 0.2rem 0.04rem;
    font-size: 0.16rem;
    display: flex;
  }
}
// 弹窗容器样式
.orderForeignTeacherPopup {
  // top: 0.81rem;
  // left: 2.1rem;
  background-color: rgba(0, 0, 0, 0.3);
  .el-dialog {
    // width: 100%;
    // min-height: 100%;
    // margin: 0 !important;
    .el-dialog__header {
      
    }
    .el-dialog__title {
      font-size: 0.25rem;
      font-weight: bold;
      color: #333333;
    }
    .el-dialog__headerbtn {
      font-size: 0.25rem !important;
    }
  }
  .el-dialog::-webkit-scrollbar {
    width: 0.1rem;
    height: 0.1rem;
  }
  .el-dialog::-webkit-scrollbar-thumb {
    border-radius: 0.5rem;
    background: #bbbbbb;
  }
  .el-dialog::-webkit-scrollbar-track {
    background: #f2f6fc;
  }
}
// 弹窗容器滚动条
.orderForeignTeacherPopup::-webkit-scrollbar {
  width: 0.1rem;
  height: 0.1rem;
}
.orderForeignTeacherPopup::-webkit-scrollbar-thumb {
  border-radius: 0.5rem;
  background: #bbbbbb;
}
.orderForeignTeacherPopup::-webkit-scrollbar-track {
  background: #f2f6fc;
}

</style>